/**
 * Created by yongqiang.ren on 2016/12/2.
 */

export class GcBaseError extends Error {
  constructor(message) {
    super(message);
    this.name = 'GcBaseError';
    this.message = message;
    Error.captureStackTrace(this, this.constructor);
  }
}

export class GcUnknownError extends GcBaseError {
  constructor(message = '好像出错了，请检查后重新试试:)') {
    super(message);
    this.name = 'GcUnknownError';
    this.message = message;
    Error.captureStackTrace(this, this.constructor);
  }
}

export class GcUniqueError extends GcBaseError {
  constructor(message = '输入内容重复了，请检查后重试') {
    super(message);
    this.name = 'GcUniqueError';
    this.message = message;
    Error.captureStackTrace(this, this.constructor);
  }
}

export class GcDependenceError extends GcBaseError {
  constructor(message = '这条数据被其它数据依赖') {
    super(message);
    this.name = 'GcDependenceError';
    this.message = message;
    Error.captureStackTrace(this, this.constructor);
  }
}

export class GcArgumentsError extends GcBaseError {
  constructor(message = '参数错误') {
    super(message);
    this.name = 'GcArgumentsError';
    this.message = message;
    Error.captureStackTrace(this, this.constructor);
  }
}

export class GcMutationForbiddenError extends GcBaseError {
  constructor(mutation) {
    let message = '你没有权限';
    if (mutation) {
      switch (mutation) {
        case 'addOrder':
          message = '你没有创建工单的权限';
          break;
        case 'addTask':
          message = '你没有创建任务的权限';
          break;
        case 'deleteOrder':
          message = '你没有删除工单的权限';
          break;
        case 'deleteTask':
          message = '你没有删除任务的权限';
          break;
        default:
      }
    }

    super(message);
    this.name = 'GcMutationForbiddenError';
    this.message = message;
    Error.captureStackTrace(this, this.constructor);
  }
}

export class GcLogisticsCannotOutError extends GcBaseError {
  constructor(message = '此物料不能出库，请检查') {
    super(message);
    this.name = 'GcLogisticsCannotOutError';
    this.message = message;
    Error.captureStackTrace(this, this.constructor);
  }
}

export class GcLogisticsCannotInError extends GcBaseError {
  constructor(message = '此物料不能入库，请检查') {
    super(message);
    this.name = 'GcLogisticsCannotInError';
    this.message = message;
    Error.captureStackTrace(this, this.constructor);
  }
}

export class GcLogisticsCannotUseError extends GcBaseError {
  constructor(message = '此物料不能投产，请检查') {
    super(message);
    this.name = 'GcLogisticsCannotUseError';
    this.message = message;
    Error.captureStackTrace(this, this.constructor);
  }
}

export class GcMaterialDependentCycleError extends GcBaseError {
  constructor(message = '循环依赖了') {
    super(message);
    this.name = 'GcMaterialDependentCycleError';
    this.message = message;
    Error.captureStackTrace(this, this.constructor);
  }
}

export class GcCreateLgUnitWithIllegalQrCodeError extends GcBaseError {
  constructor(message = '此二维码无效') {
    super(message);
    this.name = 'GcCreateLgUnitWithIllegalQrCodeError';
    this.message = message;
    Error.captureStackTrace(this, this.constructor);
  }
}

export default {
  GcBaseError,
  GcUnknownError,
  GcUniqueError,
  GcDependenceError,
  GcMutationForbiddenError,
  GcLogisticsCannotOutError,
  GcLogisticsCannotInError,
  GcLogisticsCannotUseError,
  GcArgumentsError,
  GcMaterialDependentCycleError,
  GcCreateLgUnitWithIllegalQrCodeError,
};
